#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

import os
import sys


def main():

    sourcefile=sys.argv[1]
    targetfile=sys.argv[2]

    
    if not os.path.exists(sourcefile):
        print('source is invalid')
        exit(1)
    if not os.path.exists(targetfile):
        print('target is invalid')
        exit(1)

    lineset = set()

    # print('ok')
    with open(sourcefile,mode='r') as source:
        for line in source:
            lineset.add(line.strip())
        source.close()

    with open(targetfile,mode='w') as target:
        target.truncate()
        for line in lineset:
            target.write(line+'\n')
        target.close()

    
if __name__=='__main__':
    main()
    
